home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / debug.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  2KB  |  107 lines

  1. /* --------------------------------- debug.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Routines that get used only for debug.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12.  
  13. static int    muldiv_flag = 0;
  14.  
  15. extern long FAR
  16. lcheck (long x, char *name, char *file, int line)
  17. {
  18.     if (x > (long)0x00007fffL) {
  19.         muldiv_flag = 1;
  20.         LogPrintf ("check> %s(%u) %s>%ld\n", file, line, name, x);
  21.         ++STATS_DEBUG;
  22.         return (0x00007fffL);
  23.     }
  24.     if (x < (long)0xffff8000L) {
  25.         muldiv_flag = 2;
  26.         LogPrintf ("check> %s(%u) %s<%ld\n", file, line, name, x);
  27.         ++STATS_DEBUG;
  28.         return (0xffff8000L);
  29.     }
  30.     return (x);
  31. }
  32.  
  33. extern int FAR
  34. fmulchk (long x, long y, char *file, int line)
  35. {
  36.     long    r, tx, ty, tr;
  37.     int    t;
  38.  
  39.     t = muldiv_flag;
  40.     muldiv_flag = 0;
  41.  
  42.     tx = lcheck (x, "x", file, line);
  43.     ty = lcheck (y, "y", file, line);
  44.     r = (tx * ty) >> FSCALE;
  45.     tr = lcheck (r, "r", file, line);
  46.     if (muldiv_flag)
  47.         LogPrintf ("fmul (%ld, %ld)= %ld\n", x, y, r);
  48.     else
  49.         muldiv_flag = t;
  50.     return ((int)tr);
  51. }
  52.  
  53. extern int FAR
  54. fdivchk (long x, long y, char *file, int line)
  55. {
  56.     long    r, tx, ty, tr;
  57.     int    t;
  58.  
  59.     t = muldiv_flag;
  60.     muldiv_flag = 0;
  61.  
  62.     tx = lcheck (x, "x", file, line);
  63.     if (y == 0L) {
  64.         muldiv_flag = 3;
  65.         LogPrintf ("check> %s(%u) y=%ld\n", file, line, y);
  66.         ++STATS_DEBUG;
  67.         tr = r = 0x00007fffL;
  68.     } else {
  69.         ty = lcheck (y, "y", file, line);
  70.         r = (tx << FSCALE) / ty;
  71.         tr = lcheck (r, "r", file, line);
  72.     }
  73.     if (muldiv_flag)
  74.         LogPrintf ("fdiv (%ld, %ld)= %ld\n", x, y, r);
  75.     else
  76.         muldiv_flag = t;
  77.     return ((int)tr);
  78. }
  79.  
  80. extern int FAR
  81. muldivchk (long x, long y, long z, char *file, int line)
  82. {
  83.     long    r, tx, ty, tz, tr;
  84.     int    t;
  85.  
  86.     t = muldiv_flag;
  87.     muldiv_flag = 0;
  88.  
  89.     tx = lcheck (x, "x", file, line);
  90.     ty = lcheck (y, "y", file, line);
  91.     if (0L == z) {
  92.         muldiv_flag = 3;
  93.         LogPrintf ("check> %s(%u) z=%ld\n", file, line, z);
  94.         ++STATS_DEBUG;
  95.         tr = r = 0x00007fffL;
  96.     } else {
  97.         tz = lcheck (z, "z", file, line);
  98.         r = (tx * ty) / tz;
  99.         tr = lcheck (r, "r", file, line);
  100.     }
  101.     if (muldiv_flag)
  102.         LogPrintf ("muldiv (%ld, %ld, %ld)= %ld\n", x, y, z, r);
  103.     else
  104.         muldiv_flag = t;
  105.     return ((int)tr);
  106. }
  107.